home *** CD-ROM | disk | FTP | other *** search
- //----------------------------------------------------
- // HelloCenteredMeasured.cs ⌐ 2001 by Charles Petzold
- //----------------------------------------------------
- using System;
- using System.Drawing;
- using System.Windows.Forms;
-
- class HelloCenteredMeasured: Form
- {
- public static void Main()
- {
- Application.Run(new HelloCenteredMeasured());
- }
- public HelloCenteredMeasured()
- {
- Text = "Saludo centrado mediante MeasureString";
- BackColor = SystemColors.Window;
- ForeColor = SystemColors.WindowText;
- ResizeRedraw = true;
- }
- protected override void OnPaint(PaintEventArgs pea)
- {
- Graphics grfx = pea.Graphics;
- string str = "íHola, mundo!";
- SizeF sizefText = grfx.MeasureString(str, Font);
-
- grfx.DrawString(str, Font, new SolidBrush(ForeColor),
- (ClientSize.Width - sizefText.Width) / 2,
- (ClientSize.Height - sizefText.Height) / 2);
- }
- }